<template>
	<view class="outer-container">
		<uni-nav-bar statusBar="true"
			backgroundColor="#ee7b2d"
			color="#fff"
			left-icon="back"
			@clickLeft="backLastPage"
			title="登录">
		</uni-nav-bar>



		<view class="content-container"
			style="background-image: url(../../static/img/login/login.jpg);
		background-size: cover;
		background-repeat: no-repeat;
		background-position: center center;
		">



			<view class="overlay">

			</view>
			<button class="btn-login"
				@tap="getUserInfo">
				微信用户登录
			</button>
		</view>

	</view>
</template>

<script>
	import backLastPage from '../../mixins/backLastPage.js'
	export default {
		data() {
			return {
				isLogin: false
			}
		},
		mixins: [backLastPage],
		methods: {
			getUserInfo() {
				uni.getUserProfile({
					desc: 'desc',
					success: ({
						userInfo
					}) => {
						// console.log(userInfo);
						getApp().globalData.userInfo = userInfo;
						this.getCode();

					},
					fail: (err) => {
						console.log(err);
					}
				})
			},

			getCode() {
				uni.login({
					success: ({
						code
					}) => {
						this.getToken(code);
						uni.showToast({
							title: '登录成功',
							icon: 'success'
						})
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/personal/personal'
							})
						}, 2000)

					}
				})
			},

			getToken(code) {
				uni.request({
					url: 'http://web.woniulab.com:8005/user/wxLogin',
					method: 'POST',
					data: {
						code,
						userInfo: getApp().globalData.userInfo,
						appId: 'wx455ecabb4375e998',
						appSecret: '50774005eca0e5027c57125397a68fe2',
					},
					success: ({
						data
					}) => {
						// console.log(data);

						uni.setStorage({
							key: 'token',
							data: data.token
						})

						uni.request({
							url: 'http://web.woniulab.com:8005/user/getUserInfo',
							method: 'GET',
							header: {
								Authorization: data.token
							},
							data: {
								token: data.token
							},
							success: ({ data }) => {
								// console.log(data);
								// getLatestUserInfo();
								console.log(data[0]);
								getApp().globalData.userInfo = data[0];
								// console.log(getApp().globalData.userInfo);

							}
						})


						// uni.request({
						// 	url: 'http://web.woniulab.com:8005/user/auth',
						// 	method: 'POST',
						// 	header:{
						// 		Authorization: data.token
						// 	},
						// 	data:{
						// 		token:data.token,
						// 		avatarUrl:getApp().globalData.userInfo.avatarUrl,
						// 		nickName:getApp().globalData.userInfo.nickName,
						// 		gender:getApp().globalData.userInfo.gender,
						// 		province:getApp().globalData.userInfo.province
						// 	},
						// 	success: ({data}) => {
						// 		console.log(data.message);
						// 	}
						// })




					}
				})
			}





		}
	}
</script>

<style lang="scss"
	scoped>
	.outer-container {
		width: 100vw;
		height: 100vh;
		position: relative;

		.loading-img {
			// top: 200rpx;
			max-width: 70vw;
			height: 500rpx;
			// margin: auto;
		}

		.content-container {
			position: relative;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;


			// position: relative;
			// top: 176rpx;
			// left: 0;
			// width: 100vw;
			height: calc(100vh - 176rpx);

			.overlay {
				position: absolute;
				top: 0;
				left: 0;
				width: 100vw;
				height: 100%;
				background-color: rgba($color: #000000, $alpha: 0.4);

			}

			.btn-login {
				position: absolute;
				width: 400rpx;
				height: 80rpx;
				line-height: 80rpx;
				font-size: 32rpx;
				color: white;
				background-color: #ee7b2d;
				box-shadow: $uni-box-shadow-button-primary;
				padding: 0;
			}
		}


	}
</style>
